<template>
  <div class="recommend">
    <div class="container">
      <h2>商品推荐</h2>
      <div class="goods-list">
        <router-link
          v-for="goods in goodsList" 
          :key="goods.id" 
          class="goods-card"
          :to="`/goods/detail?id=${goods.id}`"
        >
          <div class="goods-image">
            <img :src="goods.mainImage" :alt="goods.title">
          </div>
          <div class="goods-info">
            <h3>{{ goods.title }} {{ goods.description }}</h3>
            <p class="price">¥{{ goods.price }}</p>
          </div>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script setup>
// 接收商品列表
const props = defineProps({ 
  goodsList: {
    type: Array,
    required: true,
    default: () => []
  }
})

</script>

<style scoped>
.goods-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 24px;
  padding: 20px 0;
}

.goods-card {
  width: 100%;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.goods-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

.goods-image {
  width: 100%;
  height: 240px;
  position: relative;
  overflow: hidden;
}

.goods-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.goods-card:hover .goods-image img {
  transform: scale(1.05);
}

.goods-info {
  padding: 16px;
}

.goods-info h3 {
  font-size: 15px;
  line-height: 1.4;
  margin: 0 0 8px;
  height: 42px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: #333;
}

.price {
  color: #ff4d4f;
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.recommend {
  padding: 40px 0;
  background: #f5f5f5;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.container h2 {
  font-size: 24px;
  color: #333;
  margin-bottom: 20px;
  text-align: center;
  position: relative;
  padding-bottom: 12px;
}

.container h2::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 3px;
  background: #ff4d4f;
  border-radius: 2px;
}
</style>